home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 12 / Cream of the Crop 12 (Part II) / Cream of the Crop 12 (Part II).iso / OS2 / V15N04.ZIP / WARPCA.ZIP / WCABSRC.ZIP / CREATDIR.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-18  |  2.3 KB  |  104 lines

  1. // DCreateDirDlg -- Class implementation
  2. #include <assert.h>
  3. #include <cstring.h>
  4. #include <dir.h>
  5. #include <classlib\arrays.h>
  6. #include <owl\owlpch.h>
  7. #include <owl\dialog.h>
  8. #include <owl\edit.h>
  9. #include <owl\static.h>
  10. #include <owl\button.h>
  11. #include "resource.h"
  12. #include "filentry.h"
  13. #include "filetool.h"
  14. #include "creatdir.h"
  15.  
  16. #define DID_OK      1
  17. #define DID_CANCEL  2
  18.  
  19. DEFINE_RESPONSE_TABLE1(DCreateDirDlg, TDialog)
  20.     EV_CHILD_NOTIFY(IDC_NEW_DIR, EN_CHANGE, OnNewDirBoxChange),
  21.     EV_CHILD_NOTIFY(DID_OK, BN_CLICKED, CmOk),
  22. END_RESPONSE_TABLE;
  23.  
  24. void DCreateDirDlg::SetupWindow()
  25. {
  26.     TDialog::SetupWindow();
  27.  
  28.     SendDlgItemMsg(IDC_NEW_DIR, EM_SETTEXTLIMIT, 257, 0);
  29.     SetDlgItemText(IDC_CURRENT_DIR, lpszCurrentDir);
  30.  
  31.     WinEnableWindow(GetDlgItem(DID_OK), 0);
  32. }
  33.  
  34. void DCreateDirDlg::OnNewDirBoxChange()
  35. {
  36.     // Enable or disable OK button based on whether target box is empty.
  37.     int cc = WinQueryWindowTextLength(GetDlgItem(IDC_NEW_DIR));
  38.     WinEnableWindow(GetDlgItem(DID_OK), cc);
  39. }
  40.  
  41. void DCreateDirDlg::CmOk()
  42. {
  43.     int rc;
  44.  
  45.     char szNewDir[257];
  46.  
  47.     GetDlgItemText(IDC_NEW_DIR, szNewDir, 257);
  48.  
  49.     string strTemp = szNewDir;
  50.     // strTemp.to_upper();  HPFS dirs. are case sensitive!
  51.     string strNewDir;
  52.  
  53.     if(strTemp.length() > 0 && strTemp[1] != ':')
  54.     {
  55.         // If 'Drive' ':' provided assume this is a complete path.
  56.         // Otherwise attach working directory to this one.
  57.         strNewDir = lpszCurrentDir;
  58.         strNewDir += "\\";
  59.         strNewDir += strTemp;
  60.     }
  61.     else
  62.     {
  63.         strNewDir = strTemp;
  64.     }
  65.  
  66.     // No final '\\'
  67.     int nLen = strNewDir.length();
  68.     if(nLen > 0 && strNewDir[nLen - 1] == '\\')
  69.         strNewDir = strNewDir.substr(0, nLen - 1);
  70.  
  71. #ifdef _TESTING_
  72.     MessageBox((LPSTR)strNewDir.c_str(), "Creating New Directory", MB_OK);
  73. #endif
  74.  
  75.     rc = chdir((LPSTR)strNewDir.c_str());
  76.     if(!rc)
  77.     {
  78.         strTemp = "Directory ";
  79.         strTemp += strNewDir;
  80.         strTemp += " already exists";
  81.  
  82.         MessageBox((LPSTR)strNewDir.c_str(), "Directory Found", MB_OK);
  83.         CloseWindow(TRUE);
  84.     }
  85.     else
  86.     {
  87.         rc = SafeDirectoryCreate((LPSTR)strNewDir.c_str());
  88.         if(!rc)
  89.         {
  90.             strTemp = "Unable to create directory '";
  91.             strTemp += strNewDir;
  92.             strTemp += "'.";
  93.  
  94.             MessageBox((LPSTR)strTemp.c_str(), "Can't Create Dir.", MB_OK);
  95.             CloseWindow(FALSE);
  96.         }
  97.         else
  98.             // Otherwise, success!
  99.             CloseWindow(TRUE);
  100.     }
  101. }
  102.  
  103.  
  104.